September 22, 2015
$ts = New-Object -COMObject Microsoft.SMS.TSEnvironment $foo = $ts.Value("Foo")$ts.Value("Bar") = $bar$ts.GetVariables() | ForEach-Object {
New-Object psobject -Property @{
Name=$_;
Value=$ts.Value($_)
}
}Building on the last snippet we can write that to a JSON file on disk.
$ts.GetVariables() `
| Where-Object {$_ -notlike "_*"} `
| ForEach-Object {
New-Object psobject -Property @{
Name=$_;
Value=$ts.Value($_)
}
} `
| ConvertTo-Json `
| Set-Content 'tsVariables.json'$json = Get-Content 'tsVariables.json' | ConvertFrom-Json
$json | ForEach-Object {$ts.Value($_.Name) = $_.Value}
Written by Eric Haskins, maker of things.